package backend.product.manager;

import java.util.List;

import org.hibernate.Session;

import core.attribute.model.AttributeValue;
import core.product.model.Product;
import core.product.model.ProductAttributeDropdownValue;
import core.util.HibernateCoreUtil;

public class ProductAttributeDropdownValueManager extends HibernateCoreUtil
{
	public void save(ProductAttributeDropdownValue padv)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.saveOrUpdate(padv);
		session.getTransaction().commit();	
	}
	public ProductAttributeDropdownValue getProductAttributeDropdownValueByProductAndAttributeValue(Product p,AttributeValue av)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		ProductAttributeDropdownValue padv = null ;
		List<ProductAttributeDropdownValue> padvlst = session.createQuery("from ProductAttributeDropdownValue where product=:p and attributeValue=:av").setEntity("p", p).setEntity("av", av).list();
		if(padvlst.size() > 0)
		{
			padv = padvlst.get(0);
		}
		session.getTransaction().commit();
		return padv;
	}
}
